<?php
namespace Home\Controller;
use Think\Controller\RestController;
class IndexController extends RestController
{

    public function index()
    {
        $this->display('Index/index');
    }






    public function login()
    {
    	// dump($_GET);
    	// exit;
    		$name = $_GET['name'];
       		$pwd = $_GET['password'];

       		$list = M('user')->where(array('user'=>$name))->select();
       		// dump($list);
       		// exit;
       		$user = $list[0]['user'];
       		$pwdd = $list[0]['password'];
       		$id = $list[0]['id'];
       		 if ($name == $user && $pwd == $pwdd) {
                 $_SESSION['home']['user'] = $name;
                 $_SESSION['home']['id'] = $id;

                $data = array(
                	"code"=>1,
                	"message"=>"登入成功",
                	"data" =>array(
                  	"id"=>$list[0]['id'],
                  	"name"=>$list[0]['user'],
                  	"password"=>md5($list[0]['password']),
                  	"tel" => $list[0]['tel'],
                  	"email"=>$list[0]['email'],
                  	"sex"=>$list[0]['sex'],
                  	"login_time"=>date('Y-m-d H:i:s')
                  	)
                );
              
              $this->response($data,'json');
            }else{
                
            $data = array(
                  "code"=>0,
                  "message"=>"登入失败",
                  "data"=>"{}"
                );
              $this->response($data,'json');
          }

    	}

}